#!/usr/bin/env python3

#
# Run the test, check it completed successfully
#

from __future__ import print_function
try:
  from builtins import str
except:
  pass
from boututils.run_wrapper import shell, shell_safe, launch_safe
from boutdata.collect import collect
from sys import exit



print("Making Region Iterator test")
s, out = shell_safe("make > make.log",pipe=True)

flags = [""]
cmd = "./test_region_iterator"
code = 0 # Return code
pipe=True

for nproc in [1,2]:#Number of mpi procs
  for mthread in [1]:#Number of omp threads (not yet supported)
    print("\t{n} processors and {m} threads".format(n=nproc,m=mthread))

    for f in flags:
      # Run the case
      s, out = launch_safe(cmd+" "+f, nproc=nproc, pipe=pipe)
      if pipe:
        f = open("run.log."+str(nproc)+"."+str(mthread), "w")
        f.write(out)
        f.close()

      #If we've got here we know that cmd launched by launch_safe passed
      #as otherwise it raises.
      print("Passed")

if code == 0:
  print(" => All range iterator tests passed")
else:
  print(" => Some failed tests")

exit(code)
